home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)P / (A)P1.ADF / Polygon / save.c < prev   
C/C++ Source or Header  |  1987-05-25  |  5KB  |  156 lines

  1. /* save.c -- open a window to get filename,
  2. close it, and proceed.... */
  3.  
  4. #define PLX2 240      /* Save Window Size  */
  5. #define PLY2 100
  6.  
  7. #define CN_GAD2 3
  8. #define OK_GAD2 4
  9.  
  10. extern char filename[32];
  11.  
  12. /* define ok and cancel gadgets */
  13.  
  14. struct IntuiText oktxt2 = {3,2,JAM2,8,2,NL,(UBYTE *)" OK ",NL};
  15. struct IntuiText cntxt2 = {3,2,JAM2,0,2,NL,(UBYTE *)"Cancel",NL};
  16.  
  17. struct Gadget cn_gad2 = {
  18.    NL, 170,65, 54,11, GADGHCOMP, RELVERIFY,
  19.    BOOLGADGET, NL, NL,
  20.    &cntxt2, NL,NL, CN_GAD2, NL };
  21.  
  22. struct Gadget ok_gad2 = {
  23.    &cn_gad2, 170,50, 54,11, GADGHCOMP, RELVERIFY,
  24.    BOOLGADGET, NL, NL,
  25.    &oktxt2, NL,NL, OK_GAD2, NL };
  26.  
  27. /* define filename gadget */
  28.  
  29. #define ESTRINGSIZE 32
  30. UBYTE UndoBuffer[ESTRINGSIZE];
  31. USHORT StrVectors[] = {
  32.    -1,-1,
  33.    150,-1,
  34.    150, 12,
  35.    -1, 12,
  36.    -1, -1,
  37. };
  38.  
  39. struct Border StrBorder3 = {
  40.    -1, -1,           /* initial offsets, gadget relative */
  41.    1, 0, JAM1, /* pens (fore, back) and drawmode */
  42.    5,                /* number of vectors */
  43.    StrVectors,     /* pointer to the actual array of vectors */
  44.    NULL       /* no next Border, can point to another border */
  45. };
  46.  
  47. /* default text */
  48. UBYTE EnglBuffer[ESTRINGSIZE] = "temp.pic";
  49. struct StringInfo EnglInfo = {
  50.    EnglBuffer,    /* pointer to I/O buffer */
  51.    UndoBuffer,    /* pointer to undo buffer */
  52.    0,             /* buffer position */
  53.    ESTRINGSIZE,   /* max number of chars, including NULL */
  54.    0, 0,          /* first char in display, undo positions */
  55.    9,          /* number of chars (currently) in the buffer */
  56.    0, 0, 0,    /* position variables calculated by Intuition */
  57.    NULL,          /* no pointer to RastPort */
  58.    0,            /* not a LongInt string gadget */
  59.    NULL           /* no pointer to alternate keymap */
  60. };
  61. struct IntuiText EnglText = {
  62.    2, 2,    /* FrontPen, BackPen */
  63.    JAM1,          /* DrawMode */
  64.    0, -11,        /* LeftEdge, TopEdge (relative to gadget) */
  65.    &TestFont,     /* pointer to TextFont */
  66.    (UBYTE *) "Filename: ",    /* pointer to Text */
  67.    NL           /* no pointer to NextText */
  68. };
  69.  
  70. #define ENG_GAD 5
  71.  
  72. struct Gadget EnglStrGadget = {
  73.    &ok_gad2,             /* pointer to Next Gadget */
  74.    10, 50, 140, 11,  /* (Left Top Width Height) Hit Box */
  75.    GADGHCOMP,        /* Flags */
  76.    RELVERIFY,        /* Activation flags */
  77.    STRGADGET,        /* Type */
  78.    (APTR)&StrBorder3, /* pointer to Border Image */
  79.    NL,             /* no pointer to SelectRender */
  80.    &EnglText,        /* pointer to GadgetText */
  81.    NL,                /* no MutualExclude */
  82.    (APTR)&EnglInfo,  /* pointer to SpecialInfo */
  83.    ENG_GAD,                /*  ID */
  84.    NL              /* no pointer to special data */
  85. };
  86.  
  87. /* Used to open a Window   */
  88. struct NewWindow NewSwin = {
  89.    10,10, PLX2,PLY2, 2,BCOL, NL,    /* IDCMP set up AFTER CALL */
  90.    ACTIVATE | SMART_REFRESH,
  91.    &EnglStrGadget,NL, NL,    /* FirstGadget, CheckMark, Title  */
  92.    NL,NL,              /* MUST SET SCREEN AFTER OPENSCREEN!!! */
  93.    PLX2,PLY2,PLX2,PLY2, CUSTOMSCREEN }; /* MinW, MinH, MaxW, MaxH */
  94.  
  95.  
  96. /********************************************************************
  97. * save(window)
  98. *    This is the meat. This routine opens the save window and
  99. * retains control until the user selects the OK or CANCEL gadget.
  100. *     The calling arguement is a window pointer.  That window
  101. * is expected to have opened an IDCMP port, which save uses.
  102. ********************************************************************/
  103. int save(calling_window)
  104. struct Window *calling_window;
  105. {
  106. struct Window *cW;      /* save window handle   */
  107.  
  108. FAST struct IntuiMessage *imsg;
  109. FAST struct Gadget *igad;
  110.  
  111. FAST int class;
  112. int munge;
  113. BOOL keepon;
  114.  
  115.    /* Get screen from calling window   */
  116.    NewSwin.Screen = calling_window->WScreen;  /* NEED TO SET SCREEN!!! */
  117.    if ( ! (cW = (struct Window *)OpenWindow(&NewSwin)) ) {
  118.       return(FALSE); /* Oops...  */
  119.       }
  120.  
  121.    cW->UserPort = calling_window->UserPort;
  122.    ModifyIDCMP(cW, GADGETUP | GADGETDOWN);
  123.    keepon=TRUE;
  124.    while (keepon == TRUE) {
  125.       while (imsg=(struct IntuiMessage *)GetMsg(cW->UserPort)) {
  126.          class = imsg->Class;
  127.          ReplyMsg(imsg);
  128.          switch ( class ) {
  129.             case GADGETUP:
  130.             case GADGETDOWN:
  131.                igad =(struct Gadget *) imsg->IAddress;
  132.                switch ( igad->GadgetID ) {
  133.                   case CN_GAD2:
  134.                      munge=0;
  135.                      keepon=FALSE;
  136.                      break;
  137.                   case OK_GAD2:
  138.                      strcpy(filename,EnglBuffer);
  139.                      munge=1;
  140.                      keepon=FALSE;
  141.                      break;
  142.                   case ENG_GAD:
  143.                      strcpy(filename,EnglBuffer);
  144.                      break;
  145.                }
  146.          }
  147.       }
  148.    }
  149.    cW->UserPort = NL;
  150.    CloseWindow(cW);
  151.    if (munge==1)
  152.       return(1);
  153.    else
  154.       return(0);
  155. }
  156.